package com.threadExample;

/**
 * Created by yijy on 2017/7/27.
 */
public class PersonSynTest extends Thread{
    private Well well;
    public PersonSynTest(Well well) {
        this.well = well;
        start();
    }

    @Override
    public void run() {
        for (int i=10;i>0;i--){
            well.withdraw();
            Thread.yield();
        }
    }

    public static void main(String[] args) {
        Well well =new Well();
        PersonSynTest test[] = new PersonSynTest[10];
        for (int i=0;i<10;i++){
            test[i]=new PersonSynTest(well);
        }
    }
}

class Well{
    private int water=100;
    public synchronized void withdraw(){
        water--;
        System.out.println(Thread.currentThread().getName()+": water left "+water);
    }
}